package org.domon.attendance;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.time.DateUtils;
import org.apache.commons.lang3.time.FastDateFormat;

public class Worker implements Comparable<Worker> {
	
	private String dept;

	private String name;

	private String id;
	
	private Date date;
	
	private String stbNo;
	
	private String cardNo;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public String getDept() {
		return dept;
	}

	public void setDept(String dept) {
		this.dept = dept;
	}

	public String getStbNo() {
		return stbNo;
	}

	public void setStbNo(String stbNo) {
		this.stbNo = stbNo;
	}

	public String getCardNo() {
		return cardNo;
	}

	public void setCardNo(String cardNo) {
		this.cardNo = cardNo;
	}

	@Override
	public int compareTo(Worker o) {
		int f = this.getId().compareTo(o.getId());
		if (f == 0) {
			f = this.getDate().compareTo(o.getDate());
		}
		return f;
	}

	public static void main(String[] args) {
		Date d = new Date();//
		List<Worker> ww = new ArrayList<Worker>();
		Worker a = new Worker();
		a.setId("3");
		a.setName("a3");
		a.setDate(d);
		ww.add(a);
		a = new Worker();
		a.setId("1");
		a.setName("a1");
		a.setDate(d);
		ww.add(a);
		a = new Worker();
		a.setId("3");
		a.setName("a3");
		a.setDate(DateUtils.addDays(d, -1));
		ww.add(a);
		for (Worker worker : ww) {
			System.out.println(worker.getId() + "****" + FastDateFormat.getInstance().format(worker.getDate())); 
		}
		System.out.println("-----------------------");
		Collections.sort(ww);
		for (Worker worker : ww) {
			System.out.println(worker.getId() + "****" + FastDateFormat.getInstance().format(worker.getDate())); 
		}
	}
}
